package com.das.mechanic_base.widget;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.main.X3MainSelectServiceAdapter;
import com.das.mechanic_base.base.X3BaseSelfBottomSheetDialog;
import com.das.mechanic_base.bean.main.MainSelectServiceBean;
import com.das.mechanic_base.utils.X3ScreenUtils;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

public class X3BottomSelectQuickServiceDialog extends X3BaseSelfBottomSheetDialog implements X3MainSelectServiceAdapter.IOnSelectService, X3MemberButtonView.IOnClickAffirm {

    RecyclerView rlv_item;
    X3MemberButtonView mv_view;
    private X3MainSelectServiceAdapter serviceAdapter;

    MainSelectServiceBean serviceBean;

    public X3BottomSelectQuickServiceDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        rlv_item = getView(R.id.rlv_item);
        mv_view = getView(R.id.mv_view);

        rlv_item.setLayoutManager(new LinearLayoutManager(mContext));
        serviceAdapter = new X3MainSelectServiceAdapter(mContext);
        rlv_item.setAdapter(serviceAdapter);
        serviceAdapter.setiOnSelectService(this);

        mv_view.setiOnClickAffirm(this);
    }

    public void changeMainQuickBean(List<MainSelectServiceBean> serviceBeanList) {
        if (serviceAdapter != null) {
            serviceAdapter.changeServiceItem(serviceBeanList);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_bottom_select_quick_service_layout;
    }

    @Override
    protected int getDialogHeight() {
        return X3ScreenUtils.dipToPx(500,mContext);
    }

    @Override
    public void iOnSelectServiceItem(MainSelectServiceBean serviceBean) {
        mv_view.changeBtnStatus(!(serviceBean == null));
        this.serviceBean = serviceBean;
    }

    IOnSelectQuick iOnSelectQuick;

    public void setiOnSelectQuick(IOnSelectQuick iOnSelectQuick) {
        this.iOnSelectQuick = iOnSelectQuick;
    }

    public interface IOnSelectQuick {
        void iOnSelectQuickService(MainSelectServiceBean serviceBean);
    }

    @Override
    public void iOnClickAffirm() {
        if (serviceBean == null) {
            mv_view.reset();
            return;
        }
        dismiss();
        if (iOnSelectQuick != null) {
            iOnSelectQuick.iOnSelectQuickService(serviceBean);
        }
    }
    @Override
    protected void onStart() {
        super.onStart();
        MobclickAgent.onPageStart("选择检测项目弹窗");
    }

    @Override
    protected void onStop() {
        super.onStop();
        MobclickAgent.onPageEnd("选择检测项目弹窗");
    }

}
